package com.caoyanan.algorithm.question.zuoTraining;

import java.util.Arrays;

/**
 * @author: caoyanan
 * @time: 2021/4/25 4:30 下午
 */
public class LogarithmInputGenerator {

    public static final LogarithmInputGenerator INSTANCE = new LogarithmInputGenerator();

    public static LogarithmInputGenerator getInstance() {
        return INSTANCE;
    }

    /**
     * 生成随机有序数组
     * @param len
     * @param maxNumber
     * @return
     */
    public int[] generateRandomSortArray(int len, int maxNumber) {
        int[] res = new int[len];
        for (int i = 0; i != res.length; i++) {
            res[i] = (int) (Math.random() * maxNumber) + 1;
        }
        Arrays.sort(res);
        return res;
    }

    /**
     * 生成随机数组
     * @param len
     * @param maxNumber
     * @return
     */
    public int[] generateRandomArray(int len, int maxNumber) {
        int[] res = new int[len];
        for (int i = 0; i != res.length; i++) {
            res[i] = (int) (Math.random() * maxNumber) + 1;
        }
        return res;
    }


    public String generateLowerLetterString(int length, int max) {
        char[] chars = new char[length];
        for (int i = 0; i < length; i++) {
            chars[i] = (char) ((int) (Math.random() * max) + 'a');
        }
        return new String(chars);
    }

    /**
     * 两个数组元素是否相等
     * @param arr1
     * @param arr2
     * @return
     */
    public boolean isArrayEqual(int[] arr1, int[] arr2) {
        if (arr1 == null || arr2 == null || arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i != arr1.length; i++) {
            if (arr1[i] != arr2[i]) {
                return false;
            }
        }
        return true;
    }

}
